<template>
  <div>
    <van-toast id="login-success-toast" />
    <van-cell-group>
      <van-cell title="登录成功" />
      <van-button type="primary" @click="goToHome">点击跳转首页</van-button>
    </van-cell-group>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { useRouter } from 'vue-router';
// import { Toast } from 'vant';
const router=useRouter()
const route = useRoute();
const token = ref('');
const ID=ref('')
const retoken=ref('')

onMounted(() => {
  // const queryParams = new URLSearchParams(route.queryString);
  // const tokenFromURL = queryParams.get('token');
  const tokenFromURL=route.query.token
  const IDFromuRl=route.query.userid
  const retokenFromURL=route.query.reToken
  if (tokenFromURL) {
    ID.value=IDFromuRl
    token.value = tokenFromURL;
    retoken.value=retokenFromURL
    localStorage.setItem('token', token.value);
    localStorage.setItem('userid', ID.value);
    localStorage.setItem('retoken', retoken.value);


  //   Toast.success({
  //     message: '登录成功',
  //     id: 'login-success-toast',
  //     duration: 5000, // 显示5秒后自动关闭
  //     forbidClick: true,
  //     position: 'middle'
  //   });
  //
  //   // 5秒后自动跳转到首页
  //   setTimeout(() => {
  //     goToHome();
  //   }, 5000);
  // } else {
  //   console.warn('No token found in URL');
  }
});

const goToHome = () => {
  // 假设首页的路由是 '/'，你可以根据实际情况调整
  router.push('/');
};
</script>

<style scoped>
/* 添加一些样式，如果需要 */
</style>